Phase 3: optional agent-core TraceEvent/CostUsage emission (additive, flag-gated)#24
Conversation
…itive) Flag-gated, best-effort emission of standard agent-core TraceEvents (incl. CostUsage from backend_results) at the loop_trace write point, ALONGSIDE existing behavior. No-op unless HYRULE_ENGINEERING_AGENT_CORE_TRACE is truthy AND the optional agent-core package is installed (NOT a declared dependency; agent_core imported dynamically via importlib so 'mypy --strict src' and uv are unaffected, and CI without it skips the new test). Files: src/hyrule_engineering_loop/agent_core_trace.py (emit_loop_trace); trace.py additive call in write_loop_trace; tests/test_agent_core_trace.py. ruff + mypy --strict clean; full suite 196 passed; off by default (no behavior change). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 3112437158
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
|
||
| def write_loop_trace(state: GraphState) -> str | None: | ||
| """Write ``loop_trace.json`` beside the NOC handoff when configured.""" | ||
| emit_loop_trace(state) |
There was a problem hiding this comment.
Deduplicate agent-core events emitted from repeated trace writes
When HYRULE_ENGINEERING_AGENT_CORE_TRACE is enabled and memory_dir is set, write_loop_trace is called once in package_pr/human_signoff and again from reflection (the graph routes both terminal nodes to reflection). Because this line emits the entire accumulated state on every call and the sink appends, the same llm_outputs/gate_results/backend_results become duplicate agent-core records, so backend CostUsage will be counted twice for runs with memory enabled. Gate this to a final write or emit only new records.
Useful? React with 👍 / 👎.
What
Phase 3 of the Agent Runtime Framework rollout: emit standard
agent-coreobservabilityrecords from the engineering loop, alongside existing behavior. Higher fidelity than the
knowledge loop — engineering-loop state carries real token/USD cost in
backend_results[].cost.src/hyrule_engineering_loop/agent_core_trace.py—emit_loop_trace(state): oneTraceEventperllm_outputs/gate_results/backend_resultsitem (backend eventscarry
CostUsage), correlated bychange_idasrun_id.trace.py— additive call at the top ofwrite_loop_trace.tests/test_agent_core_trace.py.Safety / additive guarantees
HYRULE_ENGINEERING_AGENT_CORE_TRACEtruthy and theoptional
agent-corepackage. Verified:enabled()==False,emit_loop_trace→0.agent-coreis not a declared dependency — imported dynamically viaimportlib, somypy --strict srcanduvare unaffected and CI without it skips the new test(
importorskip).HYRULE_ENGINEERING_AGENT_CORE_TRACE_PATH(default
reports/agent-core-trace.jsonl).Verification (local, agent-core installed)
ruff check src testsclean,mypy --strict srcclean (33 files), full suite 196 passed(+2 new emitter tests).
Third in the series after
agent-core(contracts) andknowledgePR #20.🤖 Generated with Claude Code